using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using WCell.AuthServer.Localization;

namespace WCell.AuthServer.IPC
{
    /// <summary>
    /// Custom validator strategy for message security of the IPC service.
    /// </summary>
    internal class IPCAuthenticator : UserNamePasswordValidator
    {
        /// <summary>
        /// Validates users for the IPC service.
        /// </summary>
        /// <param name="userName">the given username</param>
        /// <param name="password">the given password</param>
        public override void Validate(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException();
            }

            var cfgUsername = AuthServerConfiguration.IPCUsername;
            var cfgPassword = AuthServerConfiguration.IPCPassword;

            if (cfgUsername != userName || cfgPassword != password)
            {
                throw new SecurityTokenException(string.Format(Resources.UnknownIPCLogin, userName, password));
            }
        }
    }

}
